package com.wechat.service;
import com.base.bean.*;
import com.base.dao.*;
import com.base.service.ClientService;
public class ReplyService {

	/** 自动回复的服务类
	 * @param args
	 */
	
	// 单例模式 start
	private volatile static ReplyService instance = null;
	private WechatReplyDao wechatReplyDao;

	


	private ReplyService() {
		wechatReplyDao = (WechatReplyDao) _BaseDao.ac.getBean("WechatReplyDao");
	}

	public static ReplyService getInstance() {
		if (instance == null) {
			synchronized (ReplyService.class) {// 1
				if (instance == null) {// 2
					instance = new ReplyService();// 3
				}
			}
		}
		return instance;
	}

	// 单例模式 end
	
	//添加文本消息
	public boolean addText(String key,String _discription,String url){
		WechatReply wp=new WechatReply();
		wp.setParent(0);
		wp.setState(0);
		wp.setUrl(url);
		wp.setUrlKey(key);
		wp.setDiscription(_discription);
		wechatReplyDao.merge(wp);
		return true;
	}
	
	//添加图文消息
	public boolean addPicText(String key,String title,String picUrl,String discription,String url){
		WechatReply wp=new WechatReply();
		wp.setUrlKey(key);
		wp.setTitle(title);
		wp.setPicture(picUrl);
		wp.setDiscription(discription);
		wp.setType(1);
		wp.setUrl(url);
		wp.setState(0);
		wp.setParent(0);
		wechatReplyDao.merge(wp);
		return true;
	}
	
	public static void main(String[] args) {

//		文本测试		type=0
//		String key="test1";
//		String url_name="微信文本测试";
//		String url="http://we.51waji.com/microhifo/wexintest.html";
//		ReplyService.getInstance().addText(key, url_name, url);

//		图文测试		type=1
		String key="2";
		String title="图文消息";
		String picUrl="http://www.hifo.com.cn/images/logo.gif";
		String discription="测试图文消息";
		String url="http://www.baidu.com";
		ReplyService.getInstance().addPicText(key, title, picUrl, discription, url);

	}

}
